import { md5 } from 'md5js'
import { $post } from '../utils/request'
import { type IUser } from '@/types/user'
import { useUserStore } from '@/store/user'
export const $Login = async (user: IUser) => {
  if (user.password) {
    user.password = md5(md5(user.password, 32).split('').reverse().join(''), 32)
  }

  const res = await $post('/api/login', user)
  if (res.code === 200 && res.msg === '登录成功') {
    const { token } = res
    const userStore = useUserStore()
    userStore.setToken(token)
  }
  return res
}
export const $Register = async (user: IUser) => {
  return await $post('/reguser', user)
}
